﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ServiceAgent.CatalogueService;
using System.ServiceModel;
using System.Collections.ObjectModel;

namespace ServiceAgent
{
    public class CatalogueServiceAgent : IDisposable
    {
        CatalogueServiceClient proxy;

        public CatalogueServiceAgent()
        {
            proxy = new CatalogueServiceClient();
        }

        #region CauLacBo
        public ObservableCollection<CauLacBoDTO> GetCauLacBoList()
        {
            try
            {
                proxy.Open();
                ObservableCollection<CauLacBoDTO> list =
                    proxy.GetCauLacBoList();
                proxy.Close();
                return list;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public CauLacBoDTO GetCauLacBoByID(int IDFilter)
        {
            try
            {
                proxy.Open();
                CauLacBoDTO obj =
                    proxy.GetCauLacBoByID(IDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public CauLacBoDTO GetCauLacBoByTen(string TenFilter)
        {
            try
            {
                proxy.Open();
                CauLacBoDTO obj =
                    proxy.GetCauLacBoByTen(TenFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveCauLacBo(CauLacBoDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.SaveCauLacBo(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveCauLacBoList(ObservableCollection<CauLacBoDTO> dtolist)
        {
            try
            {
                proxy.Open();
                proxy.SaveCauLacBoList(dtolist);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveCauLacBo(CauLacBoDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.RemoveCauLacBo(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveCauLacBo(int IDFilter)
        {
            try
            {
                proxy.Open();
                proxy.RemoveCauLacBoByID(IDFilter);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }
        #endregion

        #region ChinhSach
        public ObservableCollection<ChinhSachDTO> GetChinhSachList()
        {
            try
            {
                proxy.Open();
                ObservableCollection<ChinhSachDTO> list =
                    proxy.GetChinhSachList();
                proxy.Close();
                return list;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public ChinhSachDTO GetChinhSachByID(int IDFilter)
        {
            try
            {
                proxy.Open();
                ChinhSachDTO obj =
                    proxy.GetChinhSachByID(IDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveChinhSach(ChinhSachDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.SaveChinhSach(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveChinhSach(ChinhSachDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.RemoveChinhSach(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveChinhSach(int IDFilter)
        {
            try
            {
                proxy.Open();
                proxy.RemoveChinhSachByID(IDFilter);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }
        #endregion

        #region DVHCCap1
        public ObservableCollection<DVHCCap1DTO> GetDVHCCap1List()
        {
            try
            {
                proxy.Open();
                ObservableCollection<DVHCCap1DTO> list =
                    proxy.GetDVHCCap1List();
                proxy.Close();
                return list;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public DVHCCap1DTO GetDVHCCap1ByID(int IDFilter)
        {
            try
            {
                proxy.Open();
                DVHCCap1DTO obj =
                    proxy.GetDVHCCap1ByID(IDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public DVHCCap1DetailDTO GetDVHCCap1DetailByID(int IDFilter)
        {
            try
            {
                proxy.Open();
                DVHCCap1DetailDTO obj =
                    proxy.GetDVHCCap1DetailByID(IDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveDVHCCap1(DVHCCap1DTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.SaveDVHCCap1(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveDVHCCap1List(ObservableCollection<DVHCCap1DTO> dtolist)
        {
            try
            {
                proxy.Open();
                proxy.SaveDVHCCap1List(dtolist);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveDVHCCap1(DVHCCap1DTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.RemoveDVHCCap1(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveDVHCCap1(int IDFilter)
        {
            try
            {
                proxy.Open();
                proxy.RemoveDVHCCap1ByID(IDFilter);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }
        #endregion

        #region DVHCCap2
        public ObservableCollection<DVHCCap2DTO> GetDVHCCap2List()
        {
            try
            {
                proxy.Open();
                ObservableCollection<DVHCCap2DTO> list =
                    proxy.GetDVHCCap2List();
                proxy.Close();
                return list;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public ObservableCollection<DVHCCap2DTO> GetDVHCCap2ListByDVHCCap1ID(int IDFilter)
        {
            try
            {
                proxy.Open();
                ObservableCollection<DVHCCap2DTO> list =
                    proxy.GetDVHCCap2ListByDVHCCap1ID(IDFilter);
                proxy.Close();
                return list;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public DVHCCap2DTO GetDVHCCap2ByID(int IDFilter)
        {
            try
            {
                proxy.Open();
                DVHCCap2DTO obj =
                    proxy.GetDVHCCap2ByID(IDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }
        public void SaveDVHCCap2(DVHCCap2DTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.SaveDVHCCap2(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveDVHCCap2List(ObservableCollection<DVHCCap2DTO> dtolist)
        {
            try
            {
                proxy.Open();
                proxy.SaveDVHCCap2List(dtolist);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveDVHCCap2(DVHCCap2DTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.RemoveDVHCCap2(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveDVHCCap2(int IDFilter)
        {
            try
            {
                proxy.Open();
                proxy.RemoveDVHCCap2ByID(IDFilter);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }
        #endregion

        #region DanToc
        public ObservableCollection<DanTocDTO> GetDanTocList()
        {
            try
            {
                proxy.Open();
                ObservableCollection<DanTocDTO> list =
                    proxy.GetDanTocList();
                proxy.Close();
                return list;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public DanTocDTO GetDanTocByID(int IDFilter)
        {
            try
            {
                proxy.Open();
                DanTocDTO obj =
                    proxy.GetDanTocByID(IDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public DanTocDTO GetDanTocByTen(string TenFilter)
        {
            try
            {
                proxy.Open();
                DanTocDTO obj =
                    proxy.GetDanTocByTen(TenFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveDanToc(DanTocDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.SaveDanToc(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveDanTocList(ObservableCollection<DanTocDTO> dtolist)
        {
            try
            {
                proxy.Open();
                proxy.SaveDanTocList(dtolist);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveDanToc(DanTocDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.RemoveDanToc(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveDanToc(int IDFilter)
        {
            try
            {
                proxy.Open();
                proxy.RemoveDanTocByID(IDFilter);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }
        #endregion

        #region DonVi
        public ObservableCollection<DonViDTO> GetDonViList()
        {
            try
            {
                proxy.Open();
                ObservableCollection<DonViDTO> list =
                    proxy.GetDonViList();
                proxy.Close();
                return list;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public ObservableCollection<DonViDTO> GetDonViListByCapTruong()
        {
            try
            {
                proxy.Open();
                ObservableCollection<DonViDTO> obj =
                    proxy.GetDonViListByCapTruong();
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public ObservableCollection<DonViDTO> GetDonViListByCapDonVi()
        {
            try
            {
                proxy.Open();
                ObservableCollection<DonViDTO> obj =
                    proxy.GetDonViListByCapDonVi();
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public DonViDTO GetDonViByID(int IDFilter)
        {
            try
            {
                proxy.Open();
                DonViDTO obj =
                    proxy.GetDonViByID(IDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public DonViDTO GetDonViByTen(string TenFilter)
        {
            try
            {
                proxy.Open();
                DonViDTO obj =
                    proxy.GetDonViByTen(TenFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveDonVi(DonViDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.SaveDonVi(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveDonViList(ObservableCollection<DonViDTO> dtolist)
        {
            try
            {
                proxy.Open();
                proxy.SaveDonViList(dtolist);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveDonVi(DonViDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.RemoveDonVi(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveDonVi(int IDFilter)
        {
            try
            {
                proxy.Open();
                proxy.RemoveDonViByID(IDFilter);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }
        #endregion

        #region HoatDongDoanThe
        public ObservableCollection<HoatDongDoanTheDTO> GetHoatDongDoanTheList()
        {
            try
            {
                proxy.Open();
                ObservableCollection<HoatDongDoanTheDTO> list =
                    proxy.GetHoatDongDoanTheList();
                proxy.Close();
                return list;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public HoatDongDoanTheDTO GetHoatDongDoanTheByID(int IDFilter)
        {
            try
            {
                proxy.Open();
                HoatDongDoanTheDTO obj =
                    proxy.GetHoatDongDoanTheByID(IDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public HoatDongDoanTheDTO GetHoatDongDoanTheByTen(string TenFilter)
        {
            try
            {
                proxy.Open();
                HoatDongDoanTheDTO obj =
                    proxy.GetHoatDongDoanTheByTen(TenFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveHoatDongDoanThe(HoatDongDoanTheDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.SaveHoatDongDoanThe(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveHoatDongDoanTheList(ObservableCollection<HoatDongDoanTheDTO> dtolist)
        {
            try
            {
                proxy.Open();
                proxy.SaveHoatDongDoanTheList(dtolist);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveHoatDongDoanThe(HoatDongDoanTheDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.RemoveHoatDongDoanThe(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveHoatDongDoanThe(int IDFilter)
        {
            try
            {
                proxy.Open();
                proxy.RemoveHoatDongDoanTheByID(IDFilter);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }
        #endregion

        #region KhoaHoc
        public ObservableCollection<KhoaHocDTO> GetKhoaHocList()
        {
            try
            {
                proxy.Open();
                ObservableCollection<KhoaHocDTO> list =
                    proxy.GetKhoaHocList();
                proxy.Close();
                return list;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public KhoaHocDTO GetKhoaHocByID(int IDFilter)
        {
            try
            {
                proxy.Open();
                KhoaHocDTO obj =
                    proxy.GetKhoaHocByID(IDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public KhoaHocDTO GetKhoaHocByTen(string TenFilter)
        {
            try
            {
                proxy.Open();
                KhoaHocDTO obj =
                    proxy.GetKhoaHocByTen(TenFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public KhoaHocDTO GetKhoaHocByNamNhapHoc(int NamNhapHocFilter)
        {
            try
            {
                proxy.Open();
                KhoaHocDTO obj =
                    proxy.GetKhoaHocByNamNhapHoc(NamNhapHocFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveKhoaHoc(KhoaHocDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.SaveKhoaHoc(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveKhoaHocList(ObservableCollection<KhoaHocDTO> dtolist)
        {
            try
            {
                proxy.Open();
                proxy.SaveKhoaHocList(dtolist);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveKhoaHoc(KhoaHocDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.RemoveKhoaHoc(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveKhoaHoc(int IDFilter)
        {
            try
            {
                proxy.Open();
                proxy.RemoveKhoaHocByID(IDFilter);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }
        #endregion

        #region LoaiVanBang
        public ObservableCollection<LoaiVanBangDTO> GetLoaiVanBangList()
        {
            try
            {
                proxy.Open();
                ObservableCollection<LoaiVanBangDTO> list =
                    proxy.GetLoaiVanBangList();
                proxy.Close();
                return list;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public LoaiVanBangDTO GetLoaiVanBangByID(int IDFilter)
        {
            try
            {
                proxy.Open();
                LoaiVanBangDTO obj =
                    proxy.GetLoaiVanBangByID(IDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public LoaiVanBangDTO GetLoaiVanBangByTen(string TenFilter)
        {
            try
            {
                proxy.Open();
                LoaiVanBangDTO obj =
                    proxy.GetLoaiVanBangByTen(TenFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveLoaiVanBang(LoaiVanBangDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.SaveLoaiVanBang(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveLoaiVanBangList(ObservableCollection<LoaiVanBangDTO> dtolist)
        {
            try
            {
                proxy.Open();
                proxy.SaveLoaiVanBangList(dtolist);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveLoaiVanBang(LoaiVanBangDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.RemoveLoaiVanBang(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveLoaiVanBang(int IDFilter)
        {
            try
            {
                proxy.Open();
                proxy.RemoveLoaiVanBangByID(IDFilter);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }
        #endregion

        #region LoaiThayDoi Methods
        public ObservableCollection<LoaiThayDoiDTO> GetLoaiThayDoiList()
        {
            try
            {
                proxy.Open();
                ObservableCollection<LoaiThayDoiDTO> list =
                    proxy.GetLoaiThayDoiList();
                proxy.Close();
                return list;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public LoaiThayDoiDTO GetLoaiThayDoiByID(int IDFilter)
        {
            try
            {
                proxy.Open();
                LoaiThayDoiDTO obj =
                    proxy.GetLoaiThayDoiByID(IDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public LoaiThayDoiDTO GetLoaiThayDoiByTen(string TenFilter)
        {
            try
            {
                proxy.Open();
                LoaiThayDoiDTO obj =
                    proxy.GetLoaiThayDoiByTen(TenFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }
        #endregion

        #region Lop
        public ObservableCollection<LopDTO> GetLopList()
        {
            try
            {
                proxy.Open();
                ObservableCollection<LopDTO> list =
                    proxy.GetLopList();
                proxy.Close();
                return list;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public ObservableCollection<LopDTO> GetLopByDonViID(int DonViIDFilter)
        {
            try
            {
                proxy.Open();
                ObservableCollection<LopDTO> obj =
                    proxy.GetLopListByDonViID(DonViIDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public ObservableCollection<LopDTO> GetLopByKhoaHocID(int KhoaHocIDFilter)
        {
            try
            {
                proxy.Open();
                ObservableCollection<LopDTO> obj =
                    proxy.GetLopListByKhoaHocID(KhoaHocIDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public ObservableCollection<LopDTO> GetLopByDonViandKhoaHocID(int DonViIDFilter, int KhoaHocIDFilter)
        {
            try
            {
                proxy.Open();
                ObservableCollection<LopDTO> obj =
                    proxy.GetLopListByDonViandKhoaHocID(DonViIDFilter, KhoaHocIDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public LopDTO GetLopByID(int IDFilter)
        {
            try
            {
                proxy.Open();
                LopDTO obj =
                    proxy.GetLopByID(IDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public LopDTO GetLopByTen(string TenFilter)
        {
            try
            {
                proxy.Open();
                LopDTO obj =
                    proxy.GetLopByTen(TenFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public LopDTO GetLopByMaLop(string MaLopFilter)
        {
            try
            {
                proxy.Open();
                LopDTO obj =
                    proxy.GetLopByMalop(MaLopFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveLop(LopDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.SaveLop(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveLopList(ObservableCollection<LopDTO> dtolist)
        {
            try
            {
                proxy.Open();
                proxy.SaveLopList(dtolist);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveLop(LopDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.RemoveLop(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveLop(int IDFilter)
        {
            try
            {
                proxy.Open();
                proxy.RemoveLopByID(IDFilter);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }
        #endregion

        #region MonHoc
        public ObservableCollection<MonHocDTO> GetMonHocList()
        {
            try
            {
                proxy.Open();
                ObservableCollection<MonHocDTO> list =
                    proxy.GetMonHocList();
                proxy.Close();
                return list;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public MonHocDTO GetMonHocByID(int IDFilter)
        {
            try
            {
                proxy.Open();
                MonHocDTO obj =
                    proxy.GetMonHocByID(IDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public MonHocDTO GetMonHocByTen(string TenFilter)
        {
            try
            {
                proxy.Open();
                MonHocDTO obj =
                    proxy.GetMonHocByTen(TenFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public MonHocDTO GetMonHocByMaMonHoc(string MaMonHocFilter)
        {
            try
            {
                proxy.Open();
                MonHocDTO obj =
                    proxy.GetMonHocByMaMonHoc(MaMonHocFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveMonHoc(MonHocDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.SaveMonHoc(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveMonHocList(ObservableCollection<MonHocDTO> dtolist)
        {
            try
            {
                proxy.Open();
                proxy.SaveMonHocList(dtolist);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveMonHoc(MonHocDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.RemoveMonHoc(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveMonHoc(int IDFilter)
        {
            try
            {
                proxy.Open();
                proxy.RemoveMonHocByID(IDFilter);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }
        #endregion

        #region TonGiao
        public ObservableCollection<TonGiaoDTO> GetTonGiaoList()
        {
            try
            {
                proxy.Open();
                ObservableCollection<TonGiaoDTO> list =
                    proxy.GetTonGiaoList();
                proxy.Close();
                return list;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public TonGiaoDTO GetTonGiaoByID(int IDFilter)
        {
            try
            {
                proxy.Open();
                TonGiaoDTO obj =
                    proxy.GetTonGiaoByID(IDFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public TonGiaoDTO GetTonGiaoByTen(string TenFilter)
        {
            try
            {
                proxy.Open();
                TonGiaoDTO obj =
                    proxy.GetTonGiaoByTen(TenFilter);
                proxy.Close();
                return obj;
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveTonGiao(TonGiaoDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.SaveTonGiao(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void SaveTonGiaoList(ObservableCollection<TonGiaoDTO> dtolist)
        {
            try
            {
                proxy.Open();
                proxy.SaveTonGiaoList(dtolist);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveTonGiao(TonGiaoDTO objdto)
        {
            try
            {
                proxy.Open();
                proxy.RemoveTonGiao(objdto);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }

        public void RemoveTonGiao(int IDFilter)
        {
            try
            {
                proxy.Open();
                proxy.RemoveTonGiaoByID(IDFilter);
                proxy.Close();
            }
            catch (Exception) { throw; }
            finally
            {
                if (proxy.State == CommunicationState.Opened)
                    proxy.Abort();
            }
        }
        #endregion

        #region Disposable
        public void Dispose()
        {
            this.DisposeExistingServiceClientIfRequired();
        }

        private void DisposeExistingServiceClientIfRequired()
        {
            if (proxy != null)
            {
                try
                {
                    if (proxy.State == CommunicationState.Faulted)
                    {
                        proxy.Abort();
                    }
                    else
                    {
                        proxy.Close();
                    }
                }
                catch
                {
                    proxy.Abort();
                }

                proxy = null;
            }
        }
        #endregion
    }
}
